package com.yxx.controller.user;

import com.yxx.medicinecommon.result.ResponseResult;
import com.yxx.medicinepojo.dto.ShoppingCartDTO;
import com.yxx.medicinepojo.entity.ShoppingCart;
import com.yxx.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yuxiangxun
 * @date 2024/9/23
 * @apiNote
 */
@RestController
@Slf4j
@RequestMapping("/user/shoppingCart")
@Api(tags = "小程序端 购物车")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 查看购物车
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public ResponseResult<List<ShoppingCart>> showShoppingCartList(){
        List<ShoppingCart> list = shoppingCartService.showShoppingCartList();
        log.info("list:{}",list.toString());
        return ResponseResult.success(list);
    }

    /**
     * 添加购物车
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加到购物车")
    public ResponseResult add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.addShoppinigCart(shoppingCartDTO);
        return ResponseResult.success();
    }

    /**
     * 减少一个购物车药品
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/sub")
    @ApiOperation("删减一个购物车药品")
    public ResponseResult sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.sub(shoppingCartDTO);
        return ResponseResult.success();
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public ResponseResult deleteShoppingCart(){
        shoppingCartService.deleteShoppingCart();
        return ResponseResult.success();
    }
}
